package com.jijunpeng.finder;

import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

import butterknife.ButterKnife;

/**
 * Created by jijunpeng on 16/11/14.
 *
 * @author Ji Junpeng
 */

public class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getContentView() != 0) {
            setContentView(getContentView());
            ButterKnife.bind(this);
        }
        afterSetContentView();
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null && hasBackupBtn()) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (hasBackupBtn() && item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @LayoutRes
    protected int getContentView() {
        return 0;
    }

    protected boolean hasBackupBtn() {
        return true;
    }

    protected void afterSetContentView() {

    }
}
